package cn.yanyong.org.basic.base.service.impl;

import cn.yanyong.org.basic.base.mapper.BaseMapper;
import cn.yanyong.org.basic.base.query.BaseQuery;
import cn.yanyong.org.basic.base.service.IBaseService;
import cn.yanyong.org.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;



@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void removeById(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Integer total = baseMapper.queryCount(baseQuery);
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<T>(total,rows);
    }

    @Override
    public void batchRemove(List<Long> ids) {
        baseMapper.batchRemove(ids);
    }


}
